//
//  SLUpdateWatercraftViewController.m
//  StarLight
//
//  Created by Apple on 16/8/22.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

// 说明: 更新船舶控制器

#import "SLUpdateWatercraftViewController.h"
#import "SLSelectWatercraftViewCell.h"
#import "SLSelectWatercraftBtn.h"

@interface SLUpdateWatercraftViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *barrageView;  // 弹框的View
@property (weak, nonatomic) IBOutlet UIView *halfBoatView;  // 半船配货的View
@property (weak, nonatomic) IBOutlet UIView *emptyBoatView;  // 空船找货的View
@property (weak, nonatomic) IBOutlet UIView *fullBoatView;  // 满船在行的View
@property (weak, nonatomic) IBOutlet UIView *destineView;  // 预定货物的View

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UIButton *btn;

@property (nonatomic, strong) NSArray *titleArr;

@property (nonatomic ,assign)BOOL isNoSelect;

@property (weak, nonatomic) IBOutlet UIButton *notarizeBtn;  // 确认更新按钮

@end


static NSString * const watercraftID = @"SLSelectWatercraftViewCell";

@implementation SLUpdateWatercraftViewController


#pragma mark -- 系统自动调用方法
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"更新船舶";
    
    [self setupView];
    
    self.titleArr = @[@"半船配货", @"空船找货", @"满船在行", @"预定货物"];
    
    NSIndexPath *first = [NSIndexPath indexPathForRow:0 inSection:0];
    
    [self.tableView selectRowAtIndexPath:first animated:YES scrollPosition:UITableViewScrollPositionTop];
    
    [self tableView:self.tableView didSelectRowAtIndexPath:first];
    
    // 显示导航条
    [self.navigationController setNavigationBarHidden:NO animated:YES];

    _isNoSelect = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    // 控制器View即将消失的时候隐藏导航条
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}


#pragma mark -- 手动调用方法
- (void)setupView
{
    self.tableView.delegate = self;
    
    self.tableView.dataSource = self;
    
    self.tableView.backgroundColor = [UIColor colorWithRed:255/255.0 green:253/255.0 blue:246/255.0 alpha:1];
    
    // 让tableView不能滚动
    self.tableView.scrollEnabled =NO;
    
    // 注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"SLSelectWatercraftViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:watercraftID];
    

}


#pragma mark -- 点击调用的方法

// 点击选择船舶状态调用该方法
- (IBAction)selectBtn:(UIButton *)sender {
    
    if (_isNoSelect) {
        
        self.barrageView.hidden = YES;
        
        _isNoSelect = NO;
    }else
    {
        self.barrageView.hidden = NO;
        
        _isNoSelect = YES;
    }
    
}



// 确认更新按钮点击调用该方法
- (IBAction)notarizeUpdateBtn {
    
    
}



#pragma mark -- <UITableViewDataSource>

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SLSelectWatercraftViewCell *cell = [tableView dequeueReusableCellWithIdentifier:watercraftID];
    
    [cell.contentLabel setText:[NSString stringWithFormat:@"%@", _titleArr[indexPath.row]]];
    
    return cell;
}

#pragma mark -- <UITableViewDelegate>

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.barrageView.hidden = YES;
    
    if (indexPath.row == 0) {
        
        self.halfBoatView.hidden = NO;
        self.emptyBoatView.hidden = YES;
        self.fullBoatView.hidden = YES;
        self.destineView.hidden = YES;
        self.notarizeBtn.hidden = NO;
        
    }else if (indexPath.row == 1)
    {
        self.halfBoatView.hidden = YES;
        self.emptyBoatView.hidden = NO;
        self.fullBoatView.hidden = YES;
        self.destineView.hidden = YES;
        self.notarizeBtn.hidden = NO;
        
    }else if (indexPath.row == 2)
    {
        self.halfBoatView.hidden = YES;
        self.emptyBoatView.hidden = YES;
        self.fullBoatView.hidden = NO;
        self.destineView.hidden = YES;
        self.notarizeBtn.hidden = YES;
        
    }else
    {
        self.halfBoatView.hidden = YES;
        self.emptyBoatView.hidden = YES;
        self.fullBoatView.hidden = YES;
        self.destineView.hidden = NO;
        self.notarizeBtn.hidden = NO;
    }
    
    
    [self.btn setTitle:[NSString stringWithFormat:@"%@", _titleArr[indexPath.row]] forState:UIControlStateNormal];
    
    [self.btn setImage:[UIImage imageNamed:@"v"] forState:UIControlStateNormal];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

@end
